/**
 * @desc:
 * @author: Ping
 * @date: 2025/9/12 14:46
 */

package homework_2;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @desc: Computer对象测试类
 * @author: Ping
 * @date: 2025/9/12 14:46
 */
public class Homework_2Test {

    /**
     * 从ApplicationContext中获取Computer对象，并测试其非空性
     */
    public static void main(String[] args) {
        // 加载Spring配置文件
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

        // 获取Computer对象
        Computer computer = (Computer) context.getBean("computer");

        // 测试非空性
        if (computer != null) {
            System.out.println("Computer对象创建成功，非空测试通过！");
            System.out.println("Computer对象信息：");
            computer.startup();
        } else {
            System.out.println("Computer对象为空，测试失败！");
        }

        // 验证依赖注入是否成功
        if (computer.getCpu() != null && computer.getScreen() != null) {
            System.out.println("CPU和Screen依赖注入成功！");
            System.out.println("CPU品牌：" + computer.getCpu().getBrand());
            System.out.println("屏幕尺寸：" + computer.getScreen().getSize());
        } else {
            System.out.println("" +
                    "依赖注入失败！");
        }
    }
}